package com.gonsin.gview.model.dynamic.tab;

import com.gonsin.gview.annotations.GContext;
import com.gonsin.gview.model.dynamic.DynamicView;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 将viewName设置到tab中
 * 并且预先设置props
 */
@Data
public class DynamicTabItemName implements DynamicView {

    /**
     * 指向视图的名字
     */
    private String viewName;

    /**
     * tab选项卡显示的名字
     */
    private String title;


    /**
     * 后台预先设置的props
     */
    private Map<String, Object> serverProps;

    @Override
    public String title(GContext context) {
        return title;
    }

    @Override
    public List<String> props() {
        return new ArrayList<>();
    }

    @Override
    public Map<String, Object> serverProps(GContext context) {
        return serverProps;
    }

    public static DynamicTabItemNameBuilder builder() {
        return new DynamicTabItemNameBuilder();
    }


    public static class DynamicTabItemNameBuilder {
        private String viewName;
        private String title;
        private Map<String, Object> serverProps;

        private DynamicTabItemNameBuilder() {}

        public DynamicTabItemNameBuilder viewName(String viewName) {
            this.viewName = viewName;
            return this;
        }

        public DynamicTabItemNameBuilder title(String title) {
            this.title = title;
            return this;
        }

        public DynamicTabItemNameBuilder props(String key, Object value) {
            if(serverProps == null){
                serverProps = new HashMap<>();
            }
            serverProps.put(key, value);
            return this;
        }

        public DynamicTabItemName build() {
            DynamicTabItemName dynamicTabItemName = new DynamicTabItemName();
            dynamicTabItemName.setViewName(viewName);
            dynamicTabItemName.setTitle(title);
            dynamicTabItemName.setServerProps(serverProps);
            return dynamicTabItemName;
        }
    }

}
